package com.wenjie.controller;

import com.wenjie.original.entity.common.vo.RestBaseVo;
import com.wenjie.original.entity.vo.Sku.SkuUpOrAddVo;
import com.wenjie.original.entity.vo.Sku.SkuVo;
import com.wenjie.original.service.ISkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("商品信息")
@RestController
@RequestMapping("/api/sku")
public class SkuController {

    @Autowired
    private ISkuService skuService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public RestBaseVo<SkuVo.ResVo> list(@RequestBody @Validated SkuVo.SelVo selVo) {
        return skuService.list(selVo, SkuVo.ResVo.class);
    }

    @ApiOperation("添加接口")
    @PostMapping("/add")
    public void add(@RequestBody @Validated SkuUpOrAddVo.AddVo addVo) {
        skuService.save(addVo);
    }

    @ApiOperation("修改接口")
    @PostMapping("/up")
    public void up(@RequestBody @Validated SkuUpOrAddVo.UpVo upVo) {
        skuService.updateById(upVo);
    }

    @ApiOperation("删除接口")
    @PostMapping("/del")
    public void del(@RequestBody @Validated Long id) {
        skuService.removeById(id);
    }

}
